


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>c# and liblept &mdash; Leptonica &amp; Visual Studio 2008</title>
    <link rel="stylesheet" href="_static/leptonica.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '1.68',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/sidebar.js"></script>
    <link rel="top" title="Leptonica &amp; Visual Studio 2008" href="index.html" />
    <link rel="next" title="(Optional) Building zlib, libjpeg, libpng, libtiff and giflib" href="building-image-libraries.html" />
    <link rel="prev" title="Installing gnuplot to view plots" href="installing-gnuplot.html" />
 
    <link href='http://fonts.googleapis.com/css?family=Droid+Serif:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
    <script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
    <script type="text/javascript" src="_static/sort-filter-table-compact.js"></script>
   


  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="building-image-libraries.html" title="(Optional) Building zlib, libjpeg, libpng, libtiff and giflib"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="installing-gnuplot.html" title="Installing gnuplot to view plots"
             accesskey="P">previous</a> |</li>
  <li><a href="http://www.leptonica.com">Leptonica Home</a> &raquo;</li>
  
        <li><a href="index.html">VS2008 Notes (for v1.68)</a> &raquo;</li>
 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="c-and-liblept">
<h1>c# and <span class="filesystem">liblept</span><a class="headerlink" href="#c-and-liblept" title="Permalink to this headline">¶</a></h1>
<p><span class="filesystem">vs2008\LeptonicaVS2008Samples.zip</span> contains a sample Visual Studio
Solution which shows how simple it is to call <span class="filesystem">liblept</span> functions from
c# (or any other .NET language). Unpack it to <span class="filesystem">BuildFolder</span>. You should
have:</p>
<pre class="literal-block">
BuildFolder\
  include\
  leptonica-1.68\
  LeptonicaVS2008Samples\
    deskew1bpp\
    LeptonicaCLR\
    TestLeptonica\
    LeptonicaVS2008Samples.sln
  lib\
</pre>
<p><span class="command">deskew1bpp</span> is a standard C++ Win32 Console program, using
precompiled headers, C++ strings, Unicode support, and ATL macros to
convert Unicode to null-terminated C strings. In other words, it&#8217;s a
typical Visual C++ style program. <span class="command">deskew1bpp</span> demonstrates the
problems with directly rotating 1bpp images. It shows how first
converting a b&amp;w image to gray, block convolving, rotating using area
mapping, and then thresholding back to b&amp;w yields better results.</p>
<p><span class="filesystem">LeptonicaCLR</span> contains the same basic functionality as
<span class="command">deskew1bpp</span> but written in C++/CLI. In fact two of the routines,
<tt class="docutils literal"><span class="pre">renderCC()</span></tt> and <tt class="docutils literal"><span class="pre">binImageDiff()</span></tt>, are copied verbatim from
<span class="filesystem">deskew1bpp.cpp</span> showing how easy it is to port C/C++ to C++/CLI. The
resultant DLL is a bridge between the native <span class="filesystem">liblept</span> library and the
.NET Common Language Runtime (CLR). It calls native code while at the
same time exposing functions to c#. The main difference from a normal
DLL is that <span class="filesystem">LeptonicaCLR.cpp</span> is compiled with the <tt class="docutils literal"><span class="pre">/clr</span></tt> switch.</p>
<p><span class="command">TestLeptonica</span> is a c# program that has a Reference to the
<span class="filesystem">LeptonicaCLR</span> DLL to demonstrate calling <span class="filesystem">liblept</span> functions from
c#. It does a bit of argument checking and then calls
<tt class="docutils literal"><span class="pre">LeptonicaCLR.Utils.DeskewBinaryImage()</span></tt> to actually deskew a b&amp;w
image. If you want to be able to step into <span class="filesystem">liblept</span> functions while
debugging c#, just right-click the <em class="guilabel">TestLeptonica</em> project and
choose <em class="menuselection">P<span class="accelerator">r</span>operties</em>. Then make sure <em class="guilabel">Debug |
Enable unmanaged code debugging</em> is checked.</p>
<p>You&#8217;ll notice that the <span class="filesystem">liblept</span> project is also included in this
Solution. As explained <a class="reference internal" href="building-other-programs.html#intellisense-and-liblept"><em>above</em></a>, that&#8217;s
to allow Visual Studio&#8217;s Intellisense to correctly navigate to
<span class="filesystem">liblept</span> function definitions.</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div style="text-align: center; padding-right: 5px;">
 <a href="http://www.leptonica.com" >
  <img src="_static/moller52-smaller.jpg" border="0" alt="Leptonica Home"/>
 </a>
</div>



<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="overview.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quickstart</a></li>
<li class="toctree-l1"><a class="reference internal" href="downloading-binaries.html">Downloading <span class="filesystem">liblept</span> pre-built binaries and header files for Windows</a></li>
<li class="toctree-l1"><a class="reference internal" href="building-other-programs.html">Building programs that link with <span class="filesystem">liblept</span></a></li>
<li class="toctree-l1"><a class="reference internal" href="directory-organization.html">Directory organization</a></li>
<li class="toctree-l1"><a class="reference internal" href="vs2008-solution.html">The <span class="filesystem">liblept</span> Visual Studio 2008 Solution</a></li>
<li class="toctree-l1"><a class="reference internal" href="building-prog-dir.html">Building the <span class="filesystem">prog</span> directory programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="installing-cygwin.html">Installing Cygwin coreutils</a></li>
<li class="toctree-l1"><a class="reference internal" href="installing-irfanview.html">Installing IrfanView to view images</a></li>
<li class="toctree-l1"><a class="reference internal" href="installing-gnuplot.html">Installing gnuplot to view plots</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">c# and <span class="filesystem">liblept</span></a></li>
<li class="toctree-l1"><a class="reference internal" href="building-image-libraries.html">(Optional) Building <span class="filesystem">zlib</span>, <span class="filesystem">libjpeg</span>, <span class="filesystem">libpng</span>, <span class="filesystem">libtiff</span> and <span class="filesystem">giflib</span></a></li>
<li class="toctree-l1"><a class="reference internal" href="building-liblept.html">(Optional) Building the <span class="filesystem">liblept</span> library</a></li>
<li class="toctree-l1"><a class="reference internal" href="vs2010-notes.html">Visual Studio 2010 Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="package-contents.html">Package Contents</a></li>
<li class="toctree-l1"><a class="reference internal" href="versions.html">Version Notes</a></li>
</ul>


<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="building-image-libraries.html" title="(Optional) Building zlib, libjpeg, libpng, libtiff and giflib"
             >next</a></li>
        <li class="right" >
          <a href="installing-gnuplot.html" title="Installing gnuplot to view plots"
             >previous</a> |</li>
  <li><a href="http://www.leptonica.com">Leptonica Home</a> &raquo;</li>
  
        <li><a href="index.html">VS2008 Notes (for v1.68)</a> &raquo;</li>
 
      </ul>
    </div>
  <div class="footer">

   <span class="creativecommons">
    <a href="http://creativecommons.org/licenses/by/3.0/us/" >
      <img src="_static/creativecommons-88x31.png"
	   border="0" alt="Creative Commons License"/>
     </a>
    Leptonica by 
    <a href="http://leptonica.com/www.leptonica.org">
    Dan Bloomberg
    </a>
    is licensed under a
    <a href="http://creativecommons.org/licenses/by/3.0/us/">
     Creative Commons Attribution 3.0 United States License.
    </a>
   </span>

   
   <span class="sphinxcreditr">
   Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
   </span>
   

    <script type="text/javascript">
      _uacct = "UA-144810-1";
      urchinTracker();
    </script>
  </div>
  </body>
</html>